﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace WebPresentation
{
    public partial class Approve : System.Web.UI.Page
    {       
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                if (Session["UserID"] == null)
                {
                    Response.Redirect("LoginPage.aspx");
                }
                if (!Session["Role"].Equals("Admin"))
                {
                    Response.Redirect("DocumentUser.aspx");
                }

                
                lblDocID.Text = "1";
            }
        }

        protected void dtgApprove_SelectedIndexChanged(object sender, EventArgs e)
        {
                lblDocID.Text = dtgApprove.Rows[dtgApprove.SelectedIndex].Cells[7].Text;
        }

        protected void dtgApprove_RowEditing(object sender, GridViewEditEventArgs e)
        {
                lblDocID.Text = dtgApprove.Rows[e.NewEditIndex].Cells[7].Text;
                GridView1.DataBind(); 
        }

        protected void dtgApprove_DataBound(object sender, EventArgs e)
        {
            //if (dtgApprove.Rows.Count > 0)
            //{
            //    lblDocID.Text = dtgApprove.Rows[0].Cells[6].Text;
            //    dtgApprove.SelectedIndex = 0;
            //    GridView1.DataBind(); 
            //}
            if (dtgApprove.Rows.Count == 0)
            {
                // Define the name and type of the client scripts on the page.
                String csname1 = "PopupScript";
                Type cstype = this.GetType();

                // Get a ClientScriptManager reference from the Page class.
                ClientScriptManager cs = Page.ClientScript;

                // Check to see if the startup script is already registered.
                if (!cs.IsStartupScriptRegistered(cstype, csname1))
                {
                    StringBuilder cstext1 = new StringBuilder();
                    cstext1.Append("<script type=text/javascript> alert('No inapproved document!'); window.location.href='/Document.aspx' </");
                    cstext1.Append("script>");

                    cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
                }
            }
                
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Edit"))
            {
                
            }
        }
    }
}